package com.sanjiahantang.ythshopping.presenter;

import android.content.Context;

import com.sanjiahantang.ythshopping.config.ConfigValue;
import com.sanjiahantang.ythshopping.http.BaseDelegate;
import com.sanjiahantang.ythshopping.http.OkHttpClientManager;
import com.sanjiahantang.ythshopping.model.BestNewHotModel;
import com.sanjiahantang.ythshopping.model.BrandsModel;
import com.sanjiahantang.ythshopping.utils.Utils;
import com.sanjiahantang.ythshopping.views.BestNewHotView;
import com.sanjiahantang.ythshopping.views.BrandsView;
import com.squareup.okhttp.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by ZHY_9 on 2017/6/19.
 */

public class GoodsListMorePresenter extends BasePresenter {


    private BestNewHotView bestNewHotView;

    private BrandsView brandsView;

    private int page;

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public GoodsListMorePresenter(BestNewHotView bestNewHotView, BrandsView brandsView) {
        this.bestNewHotView = bestNewHotView;
        this.brandsView = brandsView;
        page = 1;
    }

    public void getMoreList(final Context context, String type, String url){

        Map<String, String> params = new HashMap<>();
        params.put("type", type);
        params.put("page", String.valueOf(page));
        if (type.equals("brands")){
            OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + url, params,
                    new BaseDelegate.ResultCallback<BrandsModel>() {
                        @Override
                        public void onError(Request request, Object tag, Exception e) {
                            Utils.showToast(context, e.getMessage());
                        }

                        @Override
                        public void onResponse(BrandsModel response, Object tag) {

                            brandsView.getBrandsMore(response);
                        }
                    });
        }else {
            OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + url, params,
                    new BaseDelegate.ResultCallback<BestNewHotModel>() {
                        @Override
                        public void onError(Request request, Object tag, Exception e) {

                            Utils.showToast(context, e.getMessage());
                        }

                        @Override
                        public void onResponse(BestNewHotModel response, Object tag) {
                            bestNewHotView.bestNewHotData(response);
                        }
                    });
        }

    }
}
